function DoFresh(){
	var t=new Date();
	$("#imagesecode").attr("src", "../shared/ValidateCode.aspx?number=" + t.getTime());
}
function city_emails() {
    var city = $("#select_city").val();
    var email = $("#ctl00_ContentPlaceHolder1_city_email").val();
    rule = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    if (email == "" || email == "您的Email地址") {
        alert("请填写email地址");
        return false;
    }
    else if (!rule.test(email)) {
    alert("电子邮件地址格式不正确!");
    return false;
    }
    else {
        return true;
        //TuanService.asmx/HelloWorld
      
//        $.post('TuanService.asmx/TuanService/HelloWorld', function(data) {
//            alert("提交成功！");
//        });
    }
}

function GetCookie(sName)   
  {     
      var   aCookie   =   document.cookie.split("; "); 
      for   (var   i=0;   i   <   aCookie.length;   i++)   
      {      
          var   aCrumb   =   aCookie[i].split("="); 
          if   (sName   ==   aCrumb[0])     
              return   unescape(aCrumb[1]);   
      }       
      return   null;  
  }
  function show_pinglun() {
     
	var code = $("#code").val();
	var content = $("#status").val();
	var content = content.replace(/(<(.[^>]*)>)|(&nbsp;)/g,"");
	content = encodeURI(content);
	content = content.replace(/%0A/g,'%3Cbr%3E'); 
	var vila = GetCookie("commentcode");
	//var sid = $("#sid").val();
	var pid = $("#pid").val();
	var username = $("#username").val();
	var pname = $("#pname").val();
	if(username==''){
		alert("请登录后再发表评论！");
    }
	else if(content==''){
		alert("请输入内容！");
	}
	else if(code!=vila){
		alert("验证码错误！");
	}
	else {
	    $("#btnSubmit").attr("disabled", "true");
	    $.ajax({
	        type: "POST",
	        contentType: "application/json",
	        url: "/Shared/TuanService.asmx/ReviewNew",
	        data: "{uid:'" + username + "',pid:'" + pid + "',body:'" + content + "',pname:'" + pname + "'}",
	        dataType: 'json',
	        success: function(data) {
	            alert("评论成功！");
	            location.reload();
	            $("#code").val("");
	            $("#status").val("");
	        },
	        error: function() {
	            alert("服务器出现错误！请稍后再试");
	        }

	    });
	    
//	    $.post('/Shared/TuanService.asmx/ReviewNew',
//	    {
//	        uid: username,
//	        pid: pid,
//	        body: content,
//	        pname: pname
//	    },
//	     function(data) {
//	        if (data) {
//	            alert("评论成功！");
//	            location.reload();
//	            $("#code").val("");
//	            $("#status").val("");
//	        }
//	        else {
//	            alert(data);
//	        }
//	    });
	}
}
function comment_login(){
    var uname = $("#ctl00_ContentPlaceHolder1_lgvPanle_uname").val();
    var upass = $("#ctl00_ContentPlaceHolder1_lgvPanle_upass").val();
	if(uname == "" || upass == ""){
	    alert("用户名或密码不能为空！");
	    return false;
	}
	return true;
}

function ShowShopMap(names,address,maplongitude,maplatitude)
{
 	//var names = encodeURI(names);
	//var address = encodeURI(address);
	$.openPopupLayer({name: "busform",width: 450,url: "/website/ajaxloader/o/public",parameters:{names:names,address:address,maplongitude:maplongitude,maplatitude:maplatitude,act:'webact'}});
}
function ShowSenMail(id, pname) {
 	//var names = encodeURI(names);
	//var address = encodeURI(address);
	$.openPopupLayer({name: "mailform",width: 450,url: "/website/ajaxloader/o/public",parameters:{id:id,pname:pname,act:'sendmail'}});
}
function mailshare(url)
{
 	//var names = encodeURI(names);
	//var address = encodeURI(address);
	$.openPopupLayer({name: "shareform",width: 450,url: "/website/ajaxloader/o/public",parameters:{url:url,act:'sharemail'}});
}

function arrive_search(){
	var start = $("#start").val();
	var end = $("#end").val();
	var arrive = $("input[name='drive'][checked]").val();
	if(start==""){
		alert("出发地不能为空！");
	}
	else{
		if(arrive=="bus"){
			window.open('http://www.ftuan.com/map/b/'+start+'/'+end);
		}
		else if(arrive=="drive"){
			window.open('http://www.ftuan.com/map/d/'+start+'/'+end);
		}
	}
}
function city_email_beijing(){
	var city = "bj";
	var email = $("#city_email").val();
	rule=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;    
	if(city=="" || email=="" || email=="您的Email地址"){
		alert("请填写email地址");
	}
	else if(!rule.test(email)){     
	    alert("电子邮件地址格式不正确!");
	}
	else{
		$.post('/city/email/'+city+'/'+email, function(data){
			alert("提交成功！");
		});
	}
}
//推荐好友
function checkmails(mail){
	var mails = mail.split(';');
	var pattern = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if(mails.length>30){
		return false;
	}else{		
	    var j=0;
		for(i=0;i<mails.length;i++){
			if(!pattern.test(mails[i])){
				j = j-1;
			}else{					
				j = j+1;
			}
		}
		if(j==mails.length)
		  return true;
		else
		  return false;
	}
}
function checkEmail(mail){
   var mails = mail.split(';');
   if(mails.length>35){
       return false;
   }
}
function checkmail(id,pname){
    var username = $('#username').val();
	var mail = $('#mail').val();
	var pattern = /\s+/;
	var title=username+'推荐"'+pname+'"给你';
	var content=pname;
	if(username==""||username.length>12||pattern.test(username)){
		alert("请输入正确的用户名！");
	}else if(mail==""){
		alert("请输入邮箱！");
    }else if(checkEmail(mail)==false){
		alert("最多同时可以推荐给35个好友！");
	}else {
		   if(checkmails(mail)){
			   $.post('/coupon/share/'+encodeURI(title)+'/'+mail+'/'+id+'/'+encodeURI(username)+'/'+encodeURI(content), function(data){	
				//$("#liuyan_content").html(data);
				  if(data==1){
					  alert("发送成功");
					  $.closePopupLayer('mailform');
				  }else{
					 // alert(data);
					  alert("发送失败，请重试！");
				  }
			    });
		   }else{
			   alert("邮箱格式不正确，请重新输入！");
		   }
			
    }
}
function check_sendmail(storename,address,tel,business_time,end_time){
	var mail = $('#email').val();
	var pattern = /\s+/;
	var patterns = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if(address=="")
	  address=1;
	if(tel=="")
	   tel=1;
	if(business_time=="")
	  business_time=1;
	if(end_time=="")
	  end_time=1
	if(mail==""){
		alert("请输入邮箱地址！");
		$('#email').focus();
	}else if(pattern.test(mail)||!patterns.test(mail)){
		alert("请输入正确的邮箱地址！");
		$('#email').focus();
	}else{
	   	 $.post('/sendstore/self/'+encodeURI(storename)+'/'+encodeURI(address)+'/'+tel+'/'+encodeURI(business_time)+'/'+encodeURI(end_time)+'/'+mail,function(data){	
				//$("#liuyan_content").html(data);
				  if(data==1){
					  alert("发送成功！");
				  }else{
					  alert("发送失败！");
				  }
			    });
	}
}


function searchSubmit()
{
	var keyword=$("#keyword").val();
	if(keyword=="") return false;
	window.location.href="http://www.com/search/td/"+keyword;
}
function shareFriend(id,t,url,title)
{
	if(t=="renren")
	{
		window.open("http://share.renren.com/share/buttonshare.do?link="+url+"&title="+title);
	}
	else if(t=="kaixin001")
	{
		window.open("http://www.kaixin001.com/repaste/share.php?rurl="+url+"&rcontent=&rtitle="+title);
	}
	else if(t=="sina")
	{
		window.open("http://v.t.sina.com.cn/share/share.php?title="+url+"&url="+title+"&source=bookmark");
	}
	else if(t=="douban")
	{
		window.open("http://www.douban.com/recommend/?url="+url+"&title="+title);
	}
	else if(t=="google")
	{
		window.open("http://www.google.com/bookmarks/mark?op=add&bkmk="+url+"&title="+title);
	}
	else if(t=="google")
	{
		window.open("http://www.google.com/bookmarks/mark?op=add&bkmk="+url+"&title="+title);
	}
	else if(t=="baidu")
	{
		window.open("http://cang.baidu.com/do/add?it="+title+"&iu="+url+"&fr=ien#nw=1");
	}
	else if(t=="zhuaxia")
	{
		window.open("http://www.zhuaxia.com/add_channel.php?url="+url);
	}
	else if(t=="email")
	{
		window.open("/recommend/sendmail/"+id+"/"+title);
	}	
}
function showmsnqq()
{
	if($("#msnqqtype").val()==1)
	{
		$("#msnqq").show();
		$("#msnqqtype").val(2);

	}
	else
	{
		$("#msnqq").hide();
		$("#msnqqtype").val(1);
	}
}
function copy_QQ(res) {
    var copyText = res;
    if (window.clipboardData) {
        window.clipboardData.setData("Text", copyText);
        alert("复制成功!");
    }
    else {
        alert("目前只支持IE,请直接拷贝URL");
    }
}
function copy_code() 
{
	var copyText=$("#msnqqvalue").val();		
	if (window.clipboardData) 
	{
		window.clipboardData.setData("Text", copyText);
		alert("复制成功!");
	} 
	else 
	{
		alert("目前只支持IE,请直接拷贝URL");
	}
}
//退订产品邮件信息
function unsubscribe(){
	var mail = $('#usermail').val();
	var pattern = /\s+/;
	var patterns = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if(mail==""){
		alert("请输入邮箱地址！");
		$('#usermail').focus();
	}else if(pattern.test(mail)||!patterns.test(mail)){
		alert("请输入正确的邮箱地址！");
		$('#usermail').focus();
	}else{
	   	$.post('/unsubscribe/mails/'+mail,function(data){	
				//$("#liuyan_content").html(data);
				  if(data==1){
					  alert("退订成功！");
				  }else{
					  alert("此邮箱地址没有订阅，请重试！");
				  }
			    });
	}
}
//共享给好友
function sharefriend(url){
	var username = $('#username').val();
	var mail = $('#mails').val();
	var pattern = /\s+/;
	if(username==""||username.length>12||pattern.test(username)){
		alert("请输入正确的用户名！");
	}else if(mail==""){
		alert("请输入邮箱！");
    }else if(checkEmail(mail)==false){
		alert("最多同时可以推荐给30个好友！");
	}else {
		if(checkmails(mail)){
			$.post('/share/friend/'+mail+'/'+encodeURI(username)+'/'+url, function(data){	
				//$("#liuyan_content").html(data);
				if(data==1){
					  alert("发送成功");
					  $.closePopupLayer('shareform');
				  }else{
					  alert(data);
				  }
			    });
		}else{
			alert("邮箱格式不正确，请重新输入！");
		}
	}

}

function close_wen(){
	$("#wen").hide();
}

function products_refurbish() {
//    if (types == 'yes') {
//        $("#products_type").html("<div class='index_one_l_left_cont6'><div class='index_one_l_left_cont6_t f14'></div><div class='tipometer'><img src='/sites/all/themes/ftuan_theme/images/loading.gif'></div><div class='index_one_l_left_cont6_b'></div></div>");
    //    }

    var pid = $("#products_pid").val();
    var minNum = $("#products_minNum").val();
    var endDate = $("#products_endDate").val();
    var maxNum = $("#products_maxNum").val();
    endDate = endDate.replace('-', '/');
    endDate = endDate.replace('-', '/');
    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: "/Shared/TuanService.asmx/ProductRefurbish",
        data: "{pid:'" + pid + "',minNum:'" + minNum + "',maxNum:'" + maxNum + "',endDate:'" + endDate + "'}",
        dataType: 'json',
        success: function(data) {
            types = 'no';
            var result = data.d;
            if (result.indexOf("已经卖光") > -1) {
                //alert("已经卖光了哈");
                if (pInterval)
                    clearInterval(pInterval);
                if (countdown)
                    clearTimeout(countdown);
                var buyBtn = "<img src=\"/app_themes/ftuan/images/buyno.gif\" alt=\"产品已经下架，不能购买\" />";
                var buyObj = $(".index_one_l_left_cont1").get(0);
                buyObj.childNodes[1].innerHTML = buyBtn;
                $("#products_type").html(result);
                document.getElementById("RemainH").innerHTML = 0;
                document.getElementById("RemainM").innerHTML = 0;
                document.getElementById("RemainS").innerHTML = 0;
            }
            else {
                $("#products_type").html(data.d);
            }

        },
        error: function() {
            //alert("服务器出现错误！");
        }
    });
//    $.post('/Shared/TuanService.asmx/ProductRefurbish',
//    {
//        pid: pid,
//        minNum: minNum,
//        endDate: endDate
//    }, function(data) {
//        var jqueryObj = $(data);
//        // 获取message节点   
//        var message = jqueryObj.children();
//        // 获取文本内容   
//        var text = message.text();
//        // 将服务器段返回的数据动态的显示在页面上   
//        // 找到保存结果信息的节点   
//        types = 'no';
//        $("#products_type").html(text);

//    }, "xml");
   
}